package com.zeng.jiudian.servlet.newType;

import com.alibaba.fastjson.JSONObject;
import com.zeng.jiudian.bean.NewTypeModel;
import com.zeng.jiudian.service.NewTypeService;
import com.zeng.jiudian.service.impl.NewTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JJ_yo
 * @Date 2020/8/13 - 16:05
 */
@WebServlet("/back/newType/add")
public class NewTypeAddServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        String typeName = req.getParameter("typeName");
        String isShow = req.getParameter("isShow");
        String recommend = req.getParameter("recommend");

        NewTypeModel model = new NewTypeModel();
        model.setTypeName(typeName);
        model.setIsShow(isShow == null ? 0 : Integer.parseInt(isShow));
        model.setRecommend(isShow == null ? 0 : Integer.parseInt(recommend));

        NewTypeService service = new NewTypeServiceImpl();
        int count = service.add(model);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", count);
        resp.getWriter().println(jsonObject);
    }
}
